package bancosys.tec.security.impl.services.incluir;

import jmine.tec.services.annotations.Execution;
import jmine.tec.services.annotations.Input;
import jmine.tec.services.annotations.ServiceImplementor;
import jmine.tec.services.api.ActionsEnum;
import bancosys.tec.security.impl.domain.Credential;
import bancosys.tec.security.impl.domain.Group;

/**
 * Serviço de associação de grupo a credencial.
 * 
 * @author rodrigok
 */
@ServiceImplementor(action = ActionsEnum.INCLUIR)
public class GroupCredentialService {

    public static final String GROUP = "Grupo";

    public static final String CREDENTIAL = "Credencial";

    // Obrigatórios
    private Group grupo;

    private Credential credencial;

    /**
     * Executa a associação da credencial ao grupo passado.
     */
    @Execution
    public void execute() {
        this.grupo.addCredential(this.credencial);
        this.grupo.getPersister().save();
    }

    /**
     * @param grupo {@link Group}
     */
    @Input(fieldName = GROUP)
    public void setGrupo(Group grupo) {
        this.grupo = grupo;
    }

    /**
     * @param credencial {@link Credential}
     */
    @Input(fieldName = CREDENTIAL)
    public void setCredencial(Credential credencial) {
        this.credencial = credencial;
    }

}
